########################################################################
# Dockerfile to build JeeShop Run Time container images
# Based on centos
# 
# JeeShop OSchen Git : https://git.oschina.net/tempestlxc/jshop.git
########################################################################

# Set the base image to centos
FROM tutum/centos

# File Author / Maintainer
MAINTAINER tempestlxc

########################### BEGIN INSTALL JAVA WEB RUN TIME ##########################

#Update system OS
RUN yum update -y

#Add passwd
#RUN yum install -y passwd

#Add openJdk7
RUN yum install -y java-1.7.0-openjdk.x86_64

#Add web user
RUN adduser web

#TO web user
RUN su web

#RUN mkdir /home/web/InstallFile

#WORKDIR ~/InstallFile/

#Download tomcat 6
ADD http://mirror.bit.edu.cn/apache/tomcat/tomcat-6/v6.0.44/bin/apache-tomcat-6.0.44.tar.gz /home/web/InstallFile/

#open tar to /home/web
RUN tar -xvzf /home/web/InstallFile/apache-tomcat-6.0.44.tar.gz -C /home/web

RUN mv /home/web/apache-tomcat-6.0.44 /home/web/tomcat6

#exit web
RUN exit

########################### INSTALLATION END ##########################


########################### BEGIN INSTALL MARIADB ##########################

RUN echo "# MariaDB 10.0 CentOS repository list - created 2015-07-30 16:55 UTC" >> /etc/yum.repos.d/MariaDB.repo
RUN echo "# http://mariadb.org/mariadb/repositories/" >> /etc/yum.repos.d/MariaDB.repo
RUN echo "[mariadb]" >> /etc/yum.repos.d/MariaDB.repo
RUN echo "name = MariaDB" >> /etc/yum.repos.d/MariaDB.repo
RUN echo "baseurl = http://yum.mariadb.org/10.0/centos7-amd64" >> /etc/yum.repos.d/MariaDB.repo
RUN echo "gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB" >> /etc/yum.repos.d/MariaDB.repo
RUN echo "gpgcheck=0" >> /etc/yum.repos.d/MariaDB.repo

#add mysql user
RUN adduser mysql

# yum remove MariaDB-server MariaDB-client  
RUN yum -y install MariaDB-server MariaDB-client

#set mysql root password
#RUN su mysql
#RUN mysqld start&
#RUN mysqladmin -u root password 'root'
#RUN mysqld stop
#RUN exit
#add mariadb user
#RUN adduser mariadb
#RUN sed -i 's/\(MySQL server\:\/var\/lib\/mysql\:\)\/sbin\/nologin/\1\/bin\/bash/' /etc/passwd


########################### INSTALLATION END ##########################




########################### BEGIN INSTALL REDIS ##########################

#add make
RUN yum install -y make

#add gcc-c++
RUN yum install -y gcc-c++

#add tcl
RUN yum install -y tcl

#add redisAdmin user
RUN adduser redisAdmin

#Download redis 3.03
ADD http://download.redis.io/releases/redis-3.0.3.tar.gz /home/redisAdmin/

RUN tar -xvzf /home/redisAdmin/redis-3.0.3.tar.gz -C /home/redisAdmin

RUN make -C /home/redisAdmin/redis-3.0.3
#RUN make test -C /home/redisAdmin/redis-3.0.3

RUN cp /home/redisAdmin/redis-3.0.3/src/redis-server /usr/local/bin/   
RUN cp /home/redisAdmin/redis-3.0.3/src/redis-cli /usr/local/bin/

#RUN mkdir /etc/redis
#RUN mkdir /var/redis
#RUN mkdir /var/redis/log
#RUN mkdir /var/redis/run
#RUN mkdir /var/redis/6379

########################### INSTALLATION END ##########################


EXPOSE 8080
EXPOSE 3306
EXPOSE 6379

CMD /home/web/tomcat6/bin/startup.sh
CMD redis-server
CMD su mysql
CMD mysqld&